package com.controller;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.entity.SalChance;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.google.gson.Gson;
import com.service.SalChanceService;


@Controller
public class SalChanceController {
	@Autowired
	private SalChanceService salChanceService;
	/*异步查询所有*/
	//使用@responseBody注解返回异步数据
	@ResponseBody  //表示返回的数据显示输出到页面中
	@RequestMapping("getallsalc.s")
	public String getallsalc(HttpServletResponse response,Model model,
			Integer page,Integer rows) throws Exception{
		System.out.println(11111111);
		response.setContentType("text/html;charset=utf-8");
		//response.setCharacterEncoding("utf-8");
		PrintWriter out= response.getWriter();
		
		Page page1=PageHelper.startPage(3,5);
		List<SalChance> selsallist = salChanceService.selectAllSalChance();
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("salsum", page1.getTotal());
		map.put("rows", selsallist);
		Gson son=new Gson();
		model.addAttribute(out.printf(son.toJson(map)));
		return "";
	}
	
	@ResponseBody
	@RequestMapping("selallsal.s")
	public String selAllSal()throws Exception{
		
		return "";
	}
	
	@ResponseBody
	@RequestMapping("addsal.s")
	public String addsal(SalChance record,Model model,HttpServletRequest request)throws Exception{
		salChanceService.insertSelective(record);
		return "getallsalc.s";
	}
}
